import BaseView from "../../cfw/mvc/BaseView";
import LobbyController from "./LobbyController";
import SDKManager from "../../sdk/SDKManager";
import CaptureComp from "../../engine/comps/CaptureComp";
import { ResultState } from "../../sdk/SDKConfig";
import { InitValue } from "../../public/Config";
import BagManager from "../bag/BagManager";
import BigExportC from "../../sdk/appBoxAd/BigExportC";
import RedPacketC from "../../sdk/redpacket/RedPacketC";


const { ccclass, property } = cc._decorator;

@ccclass
export default class LobbyUIView extends BaseView {
    @property(CaptureComp)
    capture: CaptureComp = null;
    protected controller: LobbyController;

    start() {
        this.controller = LobbyController.instance();
        if (this.controller)
            this.controller.showNativeAd()
    }

    // update (dt) {}

    onButtonIconClick(event, data) {
        if (this.controller)
            this.controller.intoWhere(parseInt(data))
    }


    onButtonCaptureClick() {
        SDKManager.getChannel().showScreenshot(this.capture.getTextureHelper())
    }


    onShareResult(state: ResultState) {
        if (state == ResultState.YES) {
            BagManager.addCoin(InitValue.shareNum)
        }
    }

    onButtonRedPacketClick() {
        let flag = SDKManager.getChannel().isSwtichOpen()
        // flag = true;
        if (flag) {
            RedPacketC.instance().intoLayer()
        } else {
            BigExportC.instance().intoExport1(() => {
                BigExportC.instance().intoExport3()
            })
        }
    }
}
